package edu.ustb.mis.dm.impl.algorithm;

import java.util.ArrayList;
import java.util.List;
import edu.ustb.mis.dm.interfaces.algorithm.ClusterAlgorithm;
import edu.ustb.mis.dm.model.ClusterResult;

public class WCABOSFV extends TextInputAndTextOutputCABOSFV implements ClusterAlgorithm<ClusterResult> {
	public WCABOSFV(final String data_set_name) {
		super(data_set_name);
	}

	/**
	 * 计算两个元素间的差异度
	 * 
	 * @param j
	 */
	@Override
	protected float calculateDissimilarity(final int j) {
		clusterResult = clusterResultList.get(j);
		tmp_clusterResult.clearSet();
		tmp_clusterResult.init(clusterResult.getSameSet(), clusterResult.getAllSet());
		tmp_clusterResult.contrast(instance.getAttributes());
		return (tmp_clusterResult.diffSize()) / (tmp_clusterResult.allSize());
	}

	@Override
	public List<ClusterResult> cluster() {
		final int instanceListSize = instanceList.size();
		instance = instanceList.get(0);
		clusterResultList = new ArrayList<ClusterResult>();
		clusterResultList.add(new ClusterResult(instance.getClassID(), instance.getAttributes()));
		boolean flag;
		for (int i = 1; i < instanceListSize; i++) {
			flag = true;
			instance = instanceList.get(i);
			category_count = clusterResultList.size();
			for (int j = 0; j < category_count; j++) {
				dissimilarity = calculateDissimilarity(j);// 计算差异度
				if (dissimilarity <= threshhold) {
					tmp_j = j;
					tmp_dissimilarity = dissimilarity;
					this.addToExist();
					flag = false;
				}
			}
			if (flag) {
				this.addToNew(i);
			}
		}
		return clusterResultList;
	}
}
